<template>
  <div class="header-contain">
    <div class="l-content">
      <el-button
        @click="handleMenu"
        icon="el-icon-menu"
        size="mini"
        style="margin-right: 15px"
      ></el-button>
      <!-- 面包屑 -->
      <el-breadcrumb separator="/">
        <el-breadcrumb-item
          v-for="item in tabList"
          :key="item.path"
          :to="{ path: item.path }"
          >{{ item.label }}</el-breadcrumb-item
        >
      </el-breadcrumb>
    </div>
    <div class="r-content">
      <el-dropdown @command="handleCommand">
        <span class="el-dropdown-link">
          <img src="../assets/images/user.png" class="image" alt="" />
        </span>
        <el-dropdown-menu slot="dropdown">
          <el-dropdown-item>个人中心</el-dropdown-item>
          <el-dropdown-item divided command="cancle">登出</el-dropdown-item>
        </el-dropdown-menu>
      </el-dropdown>
    </div>
  </div>
</template>

<script>
import { mapState } from "vuex";
import Cookie from "js-cookie";
export default {
  methods: {
    // 收起侧边栏
    handleMenu() {
      this.$store.commit("ChangeCollapse");
    },
    // 点击登出
    handleCommand(command) {
      if (command === "cancle") {
        // 清除Cookie中的token数据
        Cookie.remove("token");
        // 清除Cookie中的menu数据
        Cookie.remove("menu");
        // 跳转到登录页
        this.$router.push("/login");
      }
    },
  },
  computed: {
    // tabList() {
    //   return this.$store.state.tab.tabList;
    // },
    ...mapState({
      tabList: (state) => state.tab.tabList,
    }),
  },
};
</script>

<style lang="less" scoped>
.header-contain {
  background-color: #333;
  height: 60px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 20px;
  .l-content {
    display: flex;
    align-items: center;
    /deep/.el-breadcrumb__item {
      .el-breadcrumb__inner {
        font-weight: normal;
        &.is-link {
          color: #666;
        }
      }
      &:last-child {
        .el-breadcrumb__inner {
          color: #fff;
        }
      }
    }
    .text {
      color: #fff;
      font-size: 14px;
      margin-left: 15px;
    }
  }
  .r-content {
    .image {
      width: 40px;
      height: 40px;
      border-radius: 50%;
    }
  }
}
.el-dropdown-link {
  cursor: pointer;
  color: #409eff;
}
.el-icon-arrow-down {
  font-size: 12px;
}
</style>
